22. Exercise: List Preference

Exercise Code

In this exercise, you will get to add a new preference of type list to allow users to change the color theme of the Visualizer app.

Exercise: T06.07-Exercise-ListPreference

List Preference

Now it's your turn to create a list preference and use array resources to hold the values and labels for the list options.

SOLUTION:
  • Add a list preference to pref_visualizer.xml
  • Add string resources for the list preference
  • Create the arrays.xml resource file to contain arrays for labels and values
  • Update onSharedPreferenceChanged to load the color